package app.android.com.wuandroidapp.playair;

import java.io.InputStream;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.RectF;

import app.android.com.wuandroidapp.R;

public class RobotAir {

		Bitmap bitmap;// 图像
		int width, height;// 飞机的尺寸
		float x, y;// 出现的位置
		float speedx, speedy;// 飞机的速度
		float screenWidth, scrreenHeight;// 屏幕大小
		boolean isLive = true;
		Context context;
		// 初始化的时候：飞机图像，飞机尺寸，加速度，出现位置
		public RobotAir(Context context, int resourceID) {
			// TODO Auto-generated constructor stub
			this.context=context;

			// 将图像专场Bitmap
			InputStream is = context.getResources().openRawResource(resourceID);
			bitmap = BitmapFactory.decodeStream(is);

			width = bitmap.getWidth();
			height = bitmap.getHeight();

			// 垂直速度
			speedy = (float) (Math.random() + 1);
		}



		public MyBullet myBullet(){
			MyBullet mBullet=new MyBullet(context, R.mipmap.buttet1, x+width/2, y+height,10);
			return mBullet;

		}
		public void init2(int screenWidth, int scrreenHeight) {
			this.screenWidth = screenWidth;
			this.scrreenHeight = scrreenHeight;

			// 计算飞机的位置

			x = (float) ((Math.random())*(screenWidth - width));
			y =-height;
		}
		public void init(int screenWidth, int scrreenHeight) {
			this.screenWidth = screenWidth;
			this.scrreenHeight = scrreenHeight;

			// 计算飞机的位置

			x = (float) ((Math.random())*(screenWidth - width));
			y =(float) ((Math.random())*(scrreenHeight -height)/2);
		}

		// 绘制自身

		public void draw(Canvas canvas) {
			if(isLive){
				canvas.drawBitmap(bitmap, x, y, null);
			}
		}

		public void move() {

			if (y > scrreenHeight) {
				y=-width;
			}
			y += speedy;

		}

		public RectF getBound(){
			RectF rf=new RectF(x,y,x+width,y+height);
			return rf;
		}
	}
